<template>

  <el-main>
  <el-row :gutter="20">
    <el-col :span="3" > <p></p></el-col>
    <el-col :span="6" :xs="24" v-for="item in listData" :key="item.blogId">
      <el-card :body-style="{ padding: '0px' }">

        <img  v-if="item.blogCover!=''" :src="item.blogCover"  class="image">
        <img  v-else :src="require('@/assets/img.png')"  class="image">
        <div style="padding: 14px;">
          <span><el-link :href="'/blog/'+item.blogId" target="_blank">{{ item.blogTitle }}</el-link></span>
          <div class="bottom clearfix">
            <time class="time"> {{item.blogCreateTime| dateYMDHMSFormat}}</time>
          </div>
        </div>
      </el-card>
    </el-col>
      <el-col :span="3" > <p></p> </el-col>
  </el-row>



    <!-- 分页组件 -->
    <div class="block">
      <el-pagination
          layout="prev, pager, next"
          :page-size="9"
          :current-page="pageParam.current"
          :total="pageParam.total"
          @next-click="nextPage"
          @prev-click="prevPage"
          @current-change="currentChange"
      >
      </el-pagination>
    </div>

  </el-main>
</template>

<script>
import {blogsGet} from "@/api/blog";

export default {
  name: "index",
  data() {
    return {
      current: 1,
      listData: '',
      // 分页参数
      pageParam: {
        total: 0,
        size: 8,
        current: 1,
        pages: 1
      }
    }
  },
  created() {
    this.getBlogList("1")
  },
  methods:{
    nextPage(){
      this.getBlogList(++this.current)
    },
    prevPage(){
      this.getBlogList(--this.current)
    },
    currentChange(val){
      /*修改当前页面为val 来自前端点击数字的值*/
      this.current = val;
      this.getBlogList(this.current);
    },
    getBlogList(page){
      blogsGet(page).then(res => {
            this.listData = res.data.records;
      }
      ).catch(err => {
            console.error(err);
          }
      )
    },
    toBlogPage(blogId){
      this.$router.push(
          {
            path: '/blog/'+blogId
          }
      )
    }
  }
}
</script>

<style scoped>
.card-img-top {

}
.el-link{
  font-size: 30px;
}
</style>
